import { IToolbarConfig, IEditorConfig } from '@wangeditor/editor'
import { UploadConfig, UploadOnceConfig } from './configType'
import useUpload from './hooks/useUpload'
const { onBeforeUpload, customUpload, requestUpload, getAttachmentUrl } =
  useUpload()

// 顶部工具栏配置
export const defaultToolbarConfig: Partial<IToolbarConfig> = {
  toolbarKeys: [
    'headerSelect',
    'blockquote',
    '|',
    'bold',
    'underline',
    'italic',
    {
      key: 'group-more-style',
      title: '更多',
      iconSvg:
        '<svg viewBox="0 0 1024 1024"><path d="M204.8 505.6m-76.8 0a76.8 76.8 0 1 0 153.6 0 76.8 76.8 0 1 0-153.6 0Z"></path><path d="M505.6 505.6m-76.8 0a76.8 76.8 0 1 0 153.6 0 76.8 76.8 0 1 0-153.6 0Z"></path><path d="M806.4 505.6m-76.8 0a76.8 76.8 0 1 0 153.6 0 76.8 76.8 0 1 0-153.6 0Z"></path></svg>',
      menuKeys: ['through', 'code', 'sup', 'sub', 'clearStyle']
    },
    'color',
    'bgColor',
    '|',
    'fontSize',
    'fontFamily',
    'lineHeight',
    '|',
    'bulletedList',
    'numberedList',
    'todo',
    {
      key: 'group-justify',
      title: '对齐',
      iconSvg:
        '<svg viewBox="0 0 1024 1024"><path d="M768 793.6v102.4H51.2v-102.4h716.8z m204.8-230.4v102.4H51.2v-102.4h921.6z m-204.8-230.4v102.4H51.2v-102.4h716.8zM972.8 102.4v102.4H51.2V102.4h921.6z"></path></svg>',
      menuKeys: [
        'justifyLeft',
        'justifyRight',
        'justifyCenter',
        'justifyJustify'
      ]
    },
    {
      key: 'group-indent',
      title: '缩进',
      iconSvg:
        '<svg viewBox="0 0 1024 1024"><path d="M0 64h1024v128H0z m384 192h640v128H384z m0 192h640v128H384z m0 192h640v128H384zM0 832h1024v128H0z m0-128V320l256 192z"></path></svg>',
      menuKeys: ['indent', 'delIndent']
    },
    '|',
    'emotion',
    'insertLink',
    {
      key: 'group-image',
      title: '图片',
      iconSvg:
        '<svg viewBox="0 0 1024 1024"><path d="M959.877 128l0.123 0.123v767.775l-0.123 0.122H64.102l-0.122-0.122V128.123l0.122-0.123h895.775zM960 64H64C28.795 64 0 92.795 0 128v768c0 35.205 28.795 64 64 64h896c35.205 0 64-28.795 64-64V128c0-35.205-28.795-64-64-64zM832 288.01c0 53.023-42.988 96.01-96.01 96.01s-96.01-42.987-96.01-96.01S682.967 192 735.99 192 832 234.988 832 288.01zM896 832H128V704l224.01-384 256 320h64l224.01-192z"></path></svg>',
      menuKeys: ['uploadImage', 'insertImage']
    },
    {
      key: 'group-video',
      title: '视频',
      iconSvg:
        '<svg viewBox="0 0 1024 1024"><path d="M981.184 160.096C837.568 139.456 678.848 128 512 128S186.432 139.456 42.816 160.096C15.296 267.808 0 386.848 0 512s15.264 244.16 42.816 351.904C186.464 884.544 345.152 896 512 896s325.568-11.456 469.184-32.096C1008.704 756.192 1024 637.152 1024 512s-15.264-244.16-42.816-351.904zM384 704V320l320 192-320 192z"></path></svg>',
      menuKeys: ['uploadVideo', 'insertVideo']
    },
    'uploadAttachment', // 需要上传功能的情况下，当前key不能被删除
    'insertTable',
    'codeBlock',
    'divider',
    '|',
    'undo',
    'redo',
    'resetMenu',
    '|',
    'newFullScreenMenu',
    'previewMenu'
  ],
  insertKeys: { index: 0, keys: [] },
  excludeKeys: []
}
export const simpleToolbarConfig: Partial<IToolbarConfig> = {
  toolbarKeys: [
    'blockquote',
    'header1',
    'header2',
    'header3',
    '|',
    'bold',
    'underline',
    'italic',
    'through',
    'color',
    'bgColor',
    'clearStyle',
    '|',
    'bulletedList',
    'numberedList',
    'todo',
    'justifyLeft',
    'justifyRight',
    'justifyCenter',
    '|',
    'insertLink',
    {
      key: 'group-image',
      title: '图片',
      iconSvg:
        '<svg viewBox="0 0 1024 1024"><path d="M959.877 128l0.123 0.123v767.775l-0.123 0.122H64.102l-0.122-0.122V128.123l0.122-0.123h895.775zM960 64H64C28.795 64 0 92.795 0 128v768c0 35.205 28.795 64 64 64h896c35.205 0 64-28.795 64-64V128c0-35.205-28.795-64-64-64zM832 288.01c0 53.023-42.988 96.01-96.01 96.01s-96.01-42.987-96.01-96.01S682.967 192 735.99 192 832 234.988 832 288.01zM896 832H128V704l224.01-384 256 320h64l224.01-192z"></path></svg>',
      menuKeys: ['insertImage', 'uploadImage']
    },
    'insertVideo',
    'uploadAttachment', // 需要上传功能的情况下，当前key不能被删除
    'insertTable',
    'codeBlock',
    '|',
    'undo',
    'redo',
    'resetMenu',
    '|',
    'newFullScreenMenu',
    'previewMenu'
  ],
  insertKeys: { index: 0, keys: [] },
  excludeKeys: []
}

// 编辑器配置
export const defaultEditorConfig: Partial<IEditorConfig> = {
  placeholder: '请输入内容...',
  readOnly: false,
  scroll: true,
  maxLength: 0,
  autoFocus: true,
  hoverbarKeys: {
    attachment: {
      menuKeys: ['downloadFile', 'previewFile'] // “下载附件”菜单
    }
  }
}

// <编辑器>上传通用配置
export const defaultUploadConfig: UploadConfig = {
  // 上传文件/图片/视频的方式，default为插件内部发送上传请求，custom为自己封装的上传请求
  uploadMode: 'custom',

  // 上传接口
  server: '/biz/plan/uploadFile',

  // 获取文件接口
  attachmentServer: '/biz/plan/getAttachmentUrl',

  // form-data fieldName ，默认值 'file'
  fieldName: 'file',

  // 最多可上传几个文件，默认为 100
  maxNumberOfFiles: 100,

  // 单个文件的最大体积限制，默认为 20M
  maxFileSize: 20 * 1024 * 1024,

  // 自定义上传参数，例如传递验证的 token 等。参数会被添加到 formData 中，一起上传到服务端。
  meta: {},

  // 将 meta 拼接到 url 参数中，默认 false
  metaWithUrl: false,

  // 自定义增加 http  header
  headers: {
    Authorization: `Bear eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJubmpjZmoiLCJzY29wZSI6WyJiaXpfc3lzIiwiYmlnX3NjcmVlbiIsInNlcnZlciIsImFsbCJdLCJkZXRhaWwiOnsiaWQiOjgzNjkxMzg3Mjg2MzYzNzUwNCwib3JnSWQiOjE1OTI2NDM3NzQsImNvcnBJZCI6bnVsbCwidXNlcm5hbWUiOiJubmpjZmoiLCJyZWFsTmFtZSI6IuWNl-WugeW4guW4guWcuuebkeedo-euoeeQhuWxgCIsInBhc3N3b3JkIjpudWxsLCJlbmFibGVkIjp0cnVlLCJhcmVhSWQiOjQ1MDEwMCwiYXJlYUxldmVsIjoyLCJvcmdUeXBlIjpudWxsLCJvcmdDb2RlIjoiIiwiZm9yZWlnblVzZXJJZCI6bnVsbCwibGV2ZWwiOm51bGwsInBob25lIjoiMTgzNzM4MTY2ODciLCJyb2xlRmxhZyI6MCwidXNlclR5cGUiOjIsInJvbGVDb2RlTGlzdCI6WyJSMDA1Il0sImF1dGhvcml0aWVzIjpbeyJhdXRob3JpdHkiOiJSMDA1In1dLCJhY2NvdW50Tm9uRXhwaXJlZCI6dHJ1ZSwiY3JlZGVudGlhbHNOb25FeHBpcmVkIjp0cnVlLCJhY2NvdW50Tm9uTG9ja2VkIjp0cnVlfSwiZXhwIjoxNjYxNzgwNTI2LCJhdXRob3JpdGllcyI6WyJSMDA1Il0sImp0aSI6ImQyMWYxZTNhLWJiNWMtNDMxZC1iODI0LTc4MTdjZDdhMWMwMSIsImNsaWVudF9pZCI6Im5pcHZ0LWFwcCJ9.UwKREujwIG_9esRoBj5v69y0tTEwfp83BbYzqvApStM`,
    'Content-Type': 'multipart/form-data'
  },

  // 跨域是否传递 cookie ，默认为 true
  withCredentials: true,

  // 超时时间，默认为 5 秒
  timeout: 5 * 1000,

  onBeforeUpload,

  customUpload,

  requestUpload,

  getAttachmentUrl
}

// <编辑器>图片上传配置
export const defaultUploadImageConfig: Partial<UploadOnceConfig> = {
  name: '图片',

  // 选择文件时的类型限制，默认为 ['image/*'] 。如不想限制，则设置为 []
  allowedFileTypes: ['image/*'],

  // 小于该值就插入 base64 格式（而不上传），默认为 2M
  base64LimitSize: 2 * 1024
}

// <编辑器>视频上传配置
export const defaultUploadVideoConfig: Partial<UploadOnceConfig> = {
  name: '视频',

  // 单个文件的最大体积限制，默认为 40M
  maxFileSize: 40 * 1024 * 1024,

  // 选择文件时的类型限制，默认为 ['video/*'] 。如不想限制，则设置为 []
  allowedFileTypes: ['video/*'],

  // 超时时间，默认为 30 秒
  timeout: 30 * 1000
}

// <编辑器>上传文件配置
export const defaultUploadFileConfig: Partial<UploadOnceConfig> = {
  name: '文件',

  // 选择文件时的类型限制
  allowedFileTypes: ['.pdf', '.word']
}
